<?php
class DashboardController extends BackendController
{
    public $active = "dashboard";

    public function actionIndex(){

        //基础统计数据
        $this->data['countOfArticle'] = $this->connection->createCommand("SELECT count(*) from rk_post where post_type = 'article'")
            ->queryScalar();
        $this->data['countOfAttachment'] = $this->connection->createCommand("SELECT count(*) from rk_post where post_type = 'attachment'")
            ->queryScalar();
        $this->data['countOfPage'] = $this->connection->createCommand("SELECT count(*) from rk_post where post_type = 'page'")
            ->queryScalar();
        $this->data['countOfTag'] = $this->connection->createCommand("SELECT count(*) from rk_post where post_type = 'tag'")
            ->queryScalar();

        //访问统计数据
        $volumekeyvlues = array();
        for ($i=-6;$i<1;$i++){
            $currentday = date("Y-m-d",strtotime($i." day"));
            $row = $this->connection->createCommand("SELECT * from rk_volume where currentday = :currentday")
                ->bindParam(":currentday",$currentday)
                ->queryRow();
            if($row == true){
                $volumekeyvlues[] = array(
                    'currentday' => $row['currentday'],
                    'pageviews'=>$row['pageviews'] ==null?0:$row['pageviews']
                );
            }else{
                $volumekeyvlues[] = array(
                    'currentday' => $currentday,
                    'pageviews'=> 0
                );
            }

        }
        $this->data['volumekeyvlues'] = $volumekeyvlues;

        $this->render("index",$this->data);
    }
}